import * as TYPE from './mutation-type';
import {Request} from '../libs/request';

let actions = {
    //加
    doAdd ({ commit }) {
        commit(TYPE.COUNTER_ADD);
    },
    //减
    doDec ({ commit }) {
        commit(TYPE.COUNTER_DEC);
    },
    //分页
    setPager({commit},option){
        commit(TYPE.SET_PAGER,option);
    },
    //通讯录列表
    getContactList({commit,state},data={}){
        if(!data.pageSize) data.pageSize = state.pager.pageSize;
        var req = Request({
            url:'/api/getContactList',
            data
        });
        req.then(function(ret){
            commit(TYPE.RECEIVE_CONTACT_LIST,ret)
        })
        return req;
    },
    //查询联系人详情
    getContactDetail({commit},contactId){
        var req = Request({
            url:'/api/getContactDetail',
            data:{contactId}
        });
        req.then(function(data){
            commit(TYPE.RECEIVE_CONTACT_DETAIL,data.detail)
        })
        return req;
    },
    //添加联系人
    addContact({commit},data){
        var req = Request({
            url:'/api/addContact',
            data
        });
        return req;
    },
    //编辑联系人
    editContact({commit},data){
        var req = Request({
            url:'/api/editContact',
            data
        })
        return req;
    },
    //删除联系人
    deleteContact({commit},contactId){
        var req = Request({
            url:'/api/deleteContact',
            data:{id:contactId}
        })
        return req;
    }
}
export default actions;